import { request } from '@/utils/request'
import type { RouteRecordRaw } from 'vue-router'

/**
 * 路由 Meta 属性说明
 * @property {string} title - 页面标题，用于面包屑、浏览器标签等显示
 * @property {string} icon - 菜单图标，对应 Arco Design 图标库
 * @property {boolean} hideInMenu - 是否在菜单中隐藏该路由
 * @property {boolean} guestAccess - 是否允许未登录用户访问
 * @property {boolean} requireTeam - 是否需要选中团队才能访问/显示
 */
interface RouteMeta {
  title?: string
  icon?: string
  hideInMenu?: boolean
  guestAccess?: boolean
  requireTeam?: boolean
  keepAlive?: boolean
  cacheKey?: (route: any) => string
}

export const routes: RouteRecordRaw[] = [
  {
    path: '/',
    component: () => import('@/layout/index.vue'),
    redirect: '/dashboard',
    children: [
      {
        path: 'dashboard',
        component: () => import('@/views/dashboard/index.vue'),
        meta: {
          title: '仪表盘',
          icon: 'dashboard'
        }
      },
      {
        path: 'missions',
        component: () => import('@/views/missions/layout.vue'),
        redirect: '/missions/projects',
        meta: {
          title: '项目管理',
          icon: 'project',
          requireTeam: true
        },
        children: [
          {
            path: 'projects',
            component: () => import('@/views/missions/projects/index.vue'),
            meta: { title: '我的项目', guestAccess: false, requireTeam: true }
          },
          {
            path: 'projects/:id',
            name: 'ProjectDetail',
            component: () => import('@/views/missions/projects/detail/index.vue'),
            meta: {
              title: '项目详情',
              guestAccess: false,
              requireTeam: true,
              hideInMenu: true,
              keepAlive: true,
              cacheKey: (route: any) => `ProjectDetail-${route.params.id}`
            }
          }
        ]
      },
      {
        path: 'team',
        meta: {
          title: '团队管理',
          icon: 'team'
        },
        redirect: '/team/info',
        children: [
          {
            path: 'info',
            name: 'TeamInfo',
            component: () => import('@/views/team/index.vue'),
            meta: {
              title: '团队信息',
              requireTeam: true
            }
          },
          {
            path: 'doc',
            component: () => import('@/views/docs/index.vue'),
            meta: {
              title: '文档中心',
              guestAccess: false,
              icon: 'doc',
              requireTeam: true
            }
          },
          {
            path: 'join',
            name: 'TeamJoin',
            component: () => import('@/views/team/join.vue'),
            meta: {
              title: '加入团队',
              requireTeam: false
            }
          }
        ]
      },
      {
        path: '/account/settings',
        component: () => import('@/views/settings/index.vue'),
        meta: {
          title: '个人设置',
          guestAccess: false,
          hideInMenu: true
        }
      }
    ]
  },
  {
    path: '/login',
    component: () => import('@/views/login/index.vue'),
    meta: { title: '登录', guestAccess: true }
  },
  {
    path: '/register',
    component: () => import('@/views/register/index.vue'),
    meta: { title: '注册', guestAccess: true }
  },
  {
    path: '/help',
    component: () => import('@/views/help/index.vue'),
    meta: { title: '帮助文档', guestAccess: true }
  },
  {
    path: '/link/:code',
    name: 'ShortLink',
    component: () => import('@/views/link/index.vue'),
    meta: {
      requireAuth: true,
      title: '链接解析'
    }
  },
  {
    path: '/403',
    component: () => import('@/views/403/index.vue'),
    meta: { title: '无权限', guestAccess: true }
  },
  {
    path: '/:pathMatch(.*)*',
    component: () => import('@/views/404/index.vue'),
    meta: { title: '您要访问的资源不存在', guestAccess: true }
  }
]

export default routes
